class Solution {
public:
    string reverseWords(string s) {
        int i=0,j=0;
        while(i<s.size())
        {
            while(i<s.size()&&s[i]!=' ')
            {
                 i++;
            }
            int begin=j,end=i-1;
            while(begin<end)
            {
                swap(s[begin++],s[end--]);
            }
             i++;
             j=i;
        }
        return s;
    }
};

class Solution {
public:
    string reverseWords(string s) {
        string str;
        int i=0,j=0;
        int ret=0;
        while(i<s.size())
        {
            while(i<s.size()&&s[i]!=' ')
            {
                 i++;
            }
            for(int x=i-1;x>=j;x--)
            {
                str.push_back(s[x]);
            }
              while (i < s.size() && s[i] == ' ') {
                i++;
                str.push_back(' ');
            }
             j=i;
        }
        return str;
    }
};